﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using FastColoredTextBoxNS;

namespace Furesoft.Styling.Design.Style.Contexts
{
    public class ColorContext : IIntellisenseContext
    {
        public List<AutocompleteItem> Init()
        {
            var items = new List<AutocompleteItem>();

            foreach (var item in Enum.GetNames(typeof(KnownColor)))
            {
                var i = new AutocompleteItem(item, GenImg(new SolidBrush(Color.FromName(item))));
                items.Add(i);
            }

            items.Add(new AutocompleteItem("rgb", null, "rgb(red, green, blue)"));
            items.Add(new AutocompleteItem("argb", null, "rgb(alpha, red, green, blue)"));

            items.Add(new AutocompleteItem("hsl", null, "hsl(hue, saturation, lightness)"));
            items.Add(new AutocompleteItem("hsla", null, "hsla(hue, saturation, lightness, alpha)"));

            return items;
        }

        private Image GenImg(Brush b)
        {
            var bmp = new Bitmap(16, 16);
            var gr = Graphics.FromImage(bmp);

            gr.FillRectangle(b, new Rectangle(0, 0, 16, 16));

            return bmp;
        }
    }
}
